package listgeneric;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class ListsGenericTests01 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ArrayList<String> list = new ArrayList<>();

        Class cls = list.getClass();

        Method method = cls.getDeclaredMethod("add",Object.class);
        //反射调用list的add方法,将100天加到集合
        method.invoke(list,100);//调用list对象的add方法,传入实际参数100
        System.out.println(list);
    }
}
